import 'package:flutter/material.dart';
import 'package:ref/ref.dart';
import '../main.dart';
import 'tour_list.dart';

// 已登陆
class HasLogin extends StatelessWidget {
  const HasLogin({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    var userInfo = rootStore.users.userInfo;
    var tourInfo = rootStore.users.tourInfo;
    return Column(
      children: [
        SizedBox(height: 20),
        RefBuilder(
          () => Text(
            '用户${userInfo.value.userName}已经登陆',
            style: TextStyle(fontSize: 22),
          ),
        ),
        SizedBox(height: 20),
        RefBuilder(() => Text('亲爱的${userInfo.value.nickName}，欢迎登陆本系统')),
        SizedBox(height: 20),
        RefBuilder(() {
          if (tourInfo.value.title != '') {
            return Column(
              children: [
                Text(
                  '您选择了：' + tourInfo.value.title,
                  style: TextStyle(fontSize: 18, color: Colors.red),
                ),
                Text(
                  tourInfo.value.desc,
                  style: TextStyle(fontSize: 14, color: Colors.black38),
                ),
                SizedBox(height: 20),
                ElevatedButton(
                  onPressed: () => rootStore.users.deleteTour(),
                  child: Text('删除'),
                ),
                SizedBox(height: 20),
              ],
            );
          } else {
            return Container();
          }
        }),
        TourList(),
        SizedBox(height: 20),
        ElevatedButton(
          onPressed: () => rootStore.users.loginOut(),
          child: Text('退出登陆'),
        ),
      ],
    );
  }
}
